package com.cyzy.server.controller.user;


import com.cyzy.common.result.Result;
import com.cyzy.pojo.dto.HuntCardDTO;
import com.cyzy.pojo.dto.HuntCardUpdateDTO;
import com.cyzy.pojo.dto.RecruitCardDTO;
import com.cyzy.pojo.dto.StarDTO;
import com.cyzy.pojo.entity.HuntCard;
import com.cyzy.pojo.entity.RecruitCard;
import com.cyzy.pojo.vo.HuntCardVO;
import com.cyzy.pojo.vo.RecruitCardVO;
import com.cyzy.server.dao.HuntCardDao;
import com.cyzy.server.dao.RecruitCardDao;
import com.cyzy.server.service.HuntCardService;
import com.cyzy.server.service.RecruitCardService;

import com.cyzy.server.service.StarService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/card")
@Slf4j
public class CardController {


    @Autowired
    private RecruitCardService recruitCardService;

    @Autowired
    private RecruitCardDao recruitCardDao;

    @Autowired
    private HuntCardService huntCardService;

    @Autowired
    private HuntCardDao huntCardDao;

    @Autowired
    private StarService starService;


    /**
     * 返回首页的帖子列表
     */
    @GetMapping("/index")
    public Result indexList(String type) {
        log.info("返回首页的帖子列表...");
        if (type.equals("hunt")) {
            List<HuntCardVO> huntCardVOS = huntCardService.selectHuntCardList();
            return Result.success(huntCardVOS, "返回首页求职列表");
        } else if (type.equals("recruit")) {
            List<RecruitCardVO> recruitCardVOS = recruitCardService.selectRecruitCardList();
            return Result.success(recruitCardVOS, "返回首页招募列表");
        }

        return Result.error("传参错误，参数名为type，值为recruit或hunt");
    }

    /**
     * 帖子详情页接口
     */
    @GetMapping("/info")
    public Result getCardDetails(String type, Integer id) {
        log.info("查询帖子详情页接口....");
        if (type.equals("hunt")) {
            HuntCard huntCard = huntCardService.selectHuntCardById(id);
            return Result.success(huntCard);
        } else if (type.equals("recruit")) {
            RecruitCard recruitCard = recruitCardService.selectRecruitCardById(id);
            return Result.success(recruitCard);
        }

        return Result.error("请检查参数名和参数值是否符合条件");
    }


    /**
     * 伪删除帖子
     */
    @GetMapping("/delete")
    public Result fakeDelete(String type, Integer id) {
        log.info("删除帖子....");
        if (type.equals("hunt")) {
            huntCardDao.fakeDeleteHuntCard(id);
            return Result.success("删除成功");
        } else if (type.equals("recruit")) {
            recruitCardDao.fakeDeleteRecruitCard(id);
            return Result.success("删除成功");
        }
        return Result.error("删除失败，请检查参数是否正确");
    }


}
